Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 891)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.03226 13.02815 13.02407 13.02005 13.01606 13.01212 13.00822 13.00437
## [9] 13.00056 12.99679 12.99307 12.98939 12.98575 12.98216 12.97862 12.97512
## [17] 12.97166 12.96825 12.96488 12.96156 12.95829 12.95506 12.95187 12.94873
## [25] 12.94564 12.94260 12.93960 12.93664 12.93374 12.93088 12.92806 12.92530
## [33] 12.92258 12.91991 12.91728 12.91470 12.91218 12.90969 12.90726 12.90488
## [41] 12.90254 12.90025 12.89801 12.89582 12.89368 12.89158 12.88954 12.88755
## [49] 12.88560 12.88371 12.88187 12.88012 12.87845 12.87685 12.87533 12.87388
## [57] 12.87250 12.87120 12.86997 12.86880 12.86770 12.86667 12.86571 12.86480
## [65] 12.86396 12.86319 12.86247 12.86181 12.86120 12.86066 12.86017 12.85973
## [73] 12.85934 12.85901 12.85873 12.85849 12.85830 12.85816 12.85806 12.85801
## [81] 12.85800 12.85803 12.85810 12.85821 12.85835 12.85853 12.85875 12.85900
## [89] 12.85928 12.85959 12.85993 12.86030 12.86070 12.86112 12.86157 12.86204
## [97] 12.86253 12.86305 12.86358 12.86421 12.86499 12.86594 12.86703 12.86827
## [105] 12.86964 12.87115 12.87277 12.87451 12.87637 12.87832 12.88037 12.88251
## [113] 12.88473 12.88703 12.88940 12.89183 12.89432 12.89686 12.89944 12.90206
## [121] 12.90471 12.90738 12.91006 12.91276 12.91546 12.91816 12.92084 12.92351
## [129] 12.92616 12.92877 12.93135 12.93388 12.93637 12.93880 12.94116 12.94346
## [137] 12.94567 12.94781 12.94985 12.95180 12.95456 12.95894 12.96479 12.97194
## [145] 12.98026 12.98957 12.99973 13.01058 13.02197 13.03373 13.04572 13.05778
## [153] 13.06976 13.08149 13.09283 13.10362 13.11370 13.12292 13.13113 13.13816
## [161] 13.14387 13.14809 13.15068 13.15272 13.15537 13.15859 13.16231 13.16649
## [169] 13.17109 13.17604 13.18130 13.18682 13.19255 13.19844 13.20444 13.21050
## [177] 13.21656 13.22258 13.22851 13.23430 13.23989 13.24524 13.25030 13.25501
## [185] 13.25932 13.26320 13.26658 13.26941 13.27165 13.27324 13.27414 13.27429
## [193] 13.27364 13.27215 13.26976 13.26643 13.26210 13.25672 13.25001 13.24181
## [201] 13.23220 13.22130 13.20921 13.19602 13.18184 13.16677 13.15090 13.13436
## [209] 13.11722 13.09960 13.08160 13.06331 13.04485 13.02630 13.00778 12.98938
## [217] 12.97121 12.95337 12.93595 12.91907 12.90282 12.88730 12.87261 12.85886
## [225] 12.84451 12.82806 12.80971 12.78964 12.76805 12.74512 12.72105 12.69602
## [233] 12.67022 12.64383 12.61706 12.59008 12.56310 12.53628 12.50983 12.48394
## [241] 12.45879 12.43457 12.41147 12.38968 12.36939 12.35078 12.33406 12.31835
## [249] 12.30268 12.28706 12.27149 12.25598 12.24053 12.22515 12.20985 12.19463
## [257] 12.17950 12.16446 12.14952 12.13470 12.11998 12.10538 12.09091 12.07657
## [265] 12.06237 12.04831 12.03441 12.02065 12.00706 11.99364 11.98039 11.96733
## [273] 11.95445 11.94226 11.93122 11.92122 11.91218 11.90400 11.89660 11.88987
## [281] 11.88373 11.87809 11.87285 11.86793 11.86322 11.85864 11.85410 11.84950
## [289] 11.84476 11.83978 11.83446 11.82873 11.82247 11.81561 11.80805 11.79970
## [297] 11.79053 11.78063 11.77007 11.75893 11.74730 11.73523 11.72282 11.71015
## [305] 11.69728 11.68430 11.67128 11.65830 11.64544 11.63278 11.62040 11.60836
## [313] 11.59676 11.58566 11.57515 11.56530 11.55618 11.54789 11.54049 11.53406
## [321] 11.52869 11.52444 11.52007 11.51438 11.50754 11.49970 11.49102 11.48166
## [329] 11.47178 11.46154 11.45110 11.44061 11.43023 11.42013 11.41046 11.40138
## [337] 11.39305 11.38562 11.37926 11.37413 11.37038 11.36818 11.36768 11.36903
## [345] 11.37241 11.37753 11.38396 11.39164 11.40048 11.41040 11.42135 11.43324
## [353] 11.44599 11.45954 11.47380 11.48871 11.50419 11.52016 11.53655 11.55330
## [361] 11.57031 11.58752 11.60485 11.62223 11.63958 11.65684 11.67392 11.69075
## [369] 11.70726 11.72337 11.73901 11.75410 11.77054 11.79010 11.81254 11.83761
## [377] 11.86504 11.89460 11.92602 11.95905 11.99346 12.02897 12.06534 12.10232
## [385] 12.13966 12.17710 12.21439 12.25129 12.28753 12.32287 12.35705 12.38983
## [393] 12.42095 12.45016 12.47721 12.50184 12.52380 12.54285 12.55873 12.57312
## [401] 12.58782 12.60276 12.61788 12.63311 12.64838 12.66363 12.67878 12.69376
## [409] 12.70852 12.72297 12.73706 12.75072 12.76387 12.77645 12.78839 12.79963
## [417] 12.81010 12.81972 12.82843 12.83616 12.84285 12.84842 12.85254 12.85499
## [425] 12.85587 12.85530 12.85339 12.85024 12.84597 12.84069 12.83451 12.82754
## [433] 12.81989 12.81167 12.80299 12.79396 12.78470 12.77530 12.76589 12.75658
## [441] 12.74746 12.73867 12.73029 12.72245 12.71526 12.70883 12.70326 12.69867
## [449] 12.69327 12.68535 12.67515 12.66291 12.64886 12.63324 12.61627 12.59820
## [457] 12.57926 12.55969 12.53972 12.51958 12.49952 12.47976 12.46054 12.44210
## [465] 12.42467 12.40849 12.39379 12.38080 12.36977 12.36093 12.35450 12.34912
## [473] 12.34327 12.33701 12.33038 12.32345 12.31626 12.30887 12.30133 12.29369
## [481] 12.28601 12.27833 12.27071 12.26321 12.25587 12.24874 12.24189 12.23536
## [489] 12.22921 12.22348 12.21823 12.21352 12.20939 12.20590 12.20309 12.20104
## [497] 12.19977 12.19936 12.19984 12.20188 12.20600 12.21207 12.21995 12.22951
## [505] 12.24061 12.25313 12.26692 12.28185 12.29779 12.31461 12.33217 12.35033
## [513] 12.36897 12.38794 12.40712 12.42637 12.44556 12.46455 12.48320 12.50140
## [521] 12.51899 12.53585 12.55184 12.56682 12.58068 12.59326 12.60444 12.61408
## [529] 12.62205 12.62821 12.63243 12.63458 12.63567 12.63681 12.63795 12.63909
## [537] 12.64021 12.64127 12.64226 12.64316 12.64394 12.64458 12.64506 12.64536
## [545] 12.64546 12.64532 12.64494 12.64429 12.64335 12.64209 12.64049 12.63853
## [553] 12.63619 12.63345 12.63029 12.62667 12.62259 12.61801 12.61292 12.60730
## [561] 12.60111 12.59435 12.58623 12.57609 12.56410 12.55041 12.53518 12.51857
## [569] 12.50074 12.48184 12.46203 12.44148 12.42033 12.39875 12.37690 12.35492
## [577] 12.33300 12.31127 12.28989 12.26904 12.24886 12.22951 12.21115 12.19394
## [585] 12.17804 12.16360 12.15079 12.13976 12.12847 12.11496 12.09945 12.08218
## [593] 12.06340 12.04333 12.02221 12.00028 11.97779 11.95495 11.93202 11.90923
## [601] 11.88681 11.86500 11.84405 11.82418 11.80563 11.78864 11.77345 11.76029
## [609] 11.74940 11.74102 11.73399 11.72701 11.72011 11.71331 11.70665 11.70015
## [617] 11.69383 11.68773 11.68188 11.67629 11.67100 11.66603 11.66141 11.65718
## [625] 11.65335 11.64995 11.64702 11.64457 11.64264 11.64125 11.64043 11.64021
## [633] 11.64062 11.64168 11.64341 11.64586 11.64904 11.65393 11.66137 11.67114
## [641] 11.68303 11.69683 11.71234 11.72934 11.74763 11.76700 11.78723 11.80813
## [649] 11.82947 11.85105 11.87266 11.89409 11.91513 11.93558 11.95522 11.97385
## [657] 11.99125 12.00722 12.02154 12.03401 12.04610 12.05936 12.07369 12.08900
## [665] 12.10520 12.12220 12.13990 12.15822 12.17705 12.19631 12.21591 12.23575
## [673] 12.25573 12.27577 12.29578 12.31566 12.33531 12.35465 12.37359 12.39202
## [681] 12.40987 12.42703 12.44341 12.45893 12.47348 12.48698 12.49933 12.51044
## [689] 12.52074 12.53072 12.54040 12.54978 12.55888 12.56771 12.57629 12.58462
## [697] 12.59271 12.60059 12.60825 12.61572 12.62300 12.63011 12.63706 12.64386
## [705] 12.65052 12.65706 12.66349 12.66981 12.67605 12.68221 12.68830 12.69434
## [713] 12.70034 12.70632 12.71210 12.71755 12.72268 12.72751 12.73207 12.73637
## [721] 12.74044 12.74429 12.74794 12.75142 12.75475 12.75794 12.76102 12.76400
## [729] 12.76692 12.76978 12.77261 12.77543 12.77826 12.78112 12.78403 12.78701
## [737] 12.79008 12.79305 12.79573 12.79812 12.80025 12.80212 12.80375 12.80516
## [745] 12.80636 12.80735 12.80817 12.80882 12.80931 12.80967 12.80989 12.81001
## [753] 12.81002 12.80996 12.80982 12.80963 12.80940 12.80914 12.80886 12.80859
## [761] 12.80834 12.80811 12.80793 12.80762 12.80701 12.80614 12.80502 12.80367
## [769] 12.80212 12.80039 12.79850 12.79648 12.79434 12.79211 12.78981 12.78747
## [777] 12.78510 12.78273 12.78038 12.77808 12.77584 12.77368 12.77164 12.76973
## [785] 12.76798 12.76640 12.76475 12.76278 12.76051 12.75796 12.75518 12.75218
## [793] 12.74899 12.74564 12.74215 12.73856 12.73490 12.73118 12.72743 12.72369
## [801] 12.71998 12.71632 12.71275 12.70929 12.70597 12.70282 12.69986 12.69713
## [809] 12.69464 12.69242 12.69051 12.68893 12.68771 12.68687 12.68623 12.68556
## [817] 12.68488 12.68419 12.68350 12.68281 12.68213 12.68147 12.68083 12.68021
## [825] 12.67962 12.67907 12.67857 12.67811 12.67770 12.67736 12.67708 12.67687
## [833] 12.67674 12.67669 12.67672 12.67685 12.67708 12.67741 12.67786 12.67842
## [841] 12.67904 12.67969 12.68035 12.68104 12.68176 12.68251 12.68330 12.68413
## [849] 12.68500 12.68593 12.68690 12.68793 12.68902 12.69017 12.69139 12.69268
## [857] 12.69404 12.69548 12.69701 12.69862 12.70032 12.70211 12.70401 12.70600
## [865] 12.70809 12.71027 12.71256 12.71493 12.71740 12.71995 12.72259 12.72532
## [873] 12.72814 12.73103 12.73401 12.73707 12.74020 12.74341 12.74669 12.75004
## [881] 12.75347 12.75696 12.76052 12.76415 12.76784 12.77159 12.77539 12.77926
## [889] 12.78319 12.78716 12.79119
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 891)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.56227 12.56010 12.55799 12.55593 12.55392 12.55197 12.55007 12.54822
## [9] 12.54643 12.54470 12.54302 12.54140 12.53983 12.53833 12.53688 12.53548
## [17] 12.53415 12.53288 12.53166 12.53051 12.52941 12.52838 12.52741 12.52650
## [25] 12.52565 12.52486 12.52414 12.52348 12.52288 12.52235 12.52188 12.52148
## [33] 12.52114 12.52087 12.52067 12.52053 12.52046 12.52046 12.52053 12.52066
## [41] 12.52087 12.52114 12.52148 12.52190 12.52238 12.52294 12.52356 12.52426
## [49] 12.52503 12.52588 12.52682 12.52788 12.52905 12.53033 12.53171 12.53321
## [57] 12.53481 12.53650 12.53830 12.54019 12.54217 12.54425 12.54641 12.54866
## [65] 12.55099 12.55339 12.55588 12.55844 12.56108 12.56378 12.56655 12.56938
## [73] 12.57228 12.57524 12.57825 12.58132 12.58443 12.58760 12.59082 12.59407
## [81] 12.59737 12.60071 12.60409 12.60750 12.61094 12.61440 12.61790 12.62142
## [89] 12.62495 12.62851 12.63208 12.63567 12.63927 12.64287 12.64648 12.65009
## [97] 12.65371 12.65732 12.66092 12.66470 12.66883 12.67327 12.67803 12.68306
## [105] 12.68837 12.69393 12.69971 12.70571 12.71190 12.71826 12.72477 12.73143
## [113] 12.73820 12.74506 12.75201 12.75902 12.76606 12.77313 12.78021 12.78727
## [121] 12.79430 12.80127 12.80817 12.81498 12.82169 12.82826 12.83469 12.84095
## [129] 12.84703 12.85290 12.85856 12.86397 12.86912 12.87399 12.87857 12.88349
## [137] 12.88936 12.89610 12.90361 12.91181 12.92062 12.92995 12.93971 12.94982
## [145] 12.96019 12.97074 12.98138 12.99202 13.00259 13.01299 13.02313 13.03294
## [153] 13.04233 13.05121 13.05949 13.06709 13.07393 13.07991 13.08496 13.08898
## [161] 13.09189 13.09455 13.09782 13.10166 13.10602 13.11084 13.11608 13.12167
## [169] 13.12758 13.13375 13.14012 13.14665 13.15329 13.15999 13.16669 13.17334
## [177] 13.17989 13.18629 13.19249 13.19844 13.20408 13.20937 13.21426 13.21869
## [185] 13.22261 13.22597 13.22872 13.23081 13.23218 13.23280 13.23259 13.23152
## [193] 13.22954 13.22658 13.22260 13.21756 13.21071 13.20151 13.19014 13.17681
## [201] 13.16172 13.14506 13.12703 13.10784 13.08768 13.06674 13.04524 13.02336
## [209] 13.00130 12.97927 12.95746 12.93607 12.91530 12.89535 12.87641 12.85869
## [217] 12.84238 12.82768 12.81479 12.80197 12.78743 12.77130 12.75374 12.73487
## [225] 12.71485 12.69382 12.67191 12.64926 12.62602 12.60234 12.57834 12.55417
## [233] 12.52998 12.50590 12.48207 12.45865 12.43575 12.41354 12.39215 12.37172
## [241] 12.35239 12.33430 12.31760 12.30242 12.28891 12.27663 12.26499 12.25395
## [249] 12.24346 12.23346 12.22392 12.21477 12.20597 12.19747 12.18921 12.18115
## [257] 12.17324 12.16542 12.15765 12.14988 12.14205 12.13411 12.12602 12.11772
## [265] 12.10917 12.10031 12.09110 12.08148 12.07226 12.06423 12.05731 12.05141
## [273] 12.04645 12.04234 12.03901 12.03637 12.03434 12.03283 12.03176 12.03105
## [281] 12.03061 12.03037 12.03023 12.03012 12.02995 12.02964 12.02910 12.02826
## [289] 12.02703 12.02532 12.02306 12.02015 12.01653 12.01209 12.00677 12.00047
## [297] 11.99316 11.98491 11.97580 11.96592 11.95536 11.94419 11.93250 11.92039
## [305] 11.90793 11.89521 11.88231 11.86933 11.85634 11.84343 11.83068 11.81819
## [313] 11.80604 11.79430 11.78308 11.77244 11.76248 11.75329 11.74494 11.73753
## [321] 11.73114 11.72585 11.72009 11.71236 11.70288 11.69187 11.67954 11.66611
## [329] 11.65179 11.63680 11.62136 11.60567 11.58996 11.57444 11.55932 11.54482
## [337] 11.53116 11.51855 11.50721 11.49735 11.48919 11.48294 11.47882 11.47705
## [345] 11.47783 11.48061 11.48462 11.48979 11.49607 11.50338 11.51165 11.52082
## [353] 11.53083 11.54159 11.55305 11.56514 11.57779 11.59094 11.60451 11.61844
## [361] 11.63266 11.64711 11.66171 11.67640 11.69112 11.70579 11.72035 11.73472
## [369] 11.74886 11.76267 11.77611 11.78909 11.80332 11.82037 11.84003 11.86207
## [377] 11.88628 11.91242 11.94028 11.96963 12.00026 12.03193 12.06444 12.09755
## [385] 12.13105 12.16470 12.19830 12.23162 12.26443 12.29652 12.32766 12.35763
## [393] 12.38620 12.41316 12.43829 12.46135 12.48214 12.50042 12.51598 12.53073
## [401] 12.54662 12.56351 12.58125 12.59969 12.61868 12.63809 12.65775 12.67752
## [409] 12.69725 12.71680 12.73601 12.75474 12.77284 12.79016 12.80656 12.82188
## [417] 12.83598 12.84871 12.85993 12.86947 12.87720 12.88297 12.88679 12.88886
## [425] 12.88927 12.88817 12.88565 12.88184 12.87685 12.87080 12.86381 12.85599
## [433] 12.84746 12.83833 12.82873 12.81876 12.80855 12.79821 12.78786 12.77761
## [441] 12.76759 12.75790 12.74866 12.74000 12.73202 12.72484 12.71859 12.71337
## [449] 12.70716 12.69803 12.68626 12.67213 12.65592 12.63790 12.61835 12.59756
## [457] 12.57578 12.55332 12.53043 12.50741 12.48452 12.46204 12.44026 12.41945
## [465] 12.39989 12.38185 12.36561 12.35146 12.33966 12.33050 12.32425 12.31926
## [473] 12.31372 12.30771 12.30128 12.29449 12.28741 12.28009 12.27260 12.26500
## [481] 12.25735 12.24971 12.24215 12.23473 12.22750 12.22053 12.21388 12.20762
## [489] 12.20180 12.19649 12.19175 12.18763 12.18421 12.18154 12.17969 12.17871
## [497] 12.17867 12.17963 12.18165 12.18540 12.19143 12.19958 12.20972 12.22170
## [505] 12.23539 12.25063 12.26729 12.28522 12.30429 12.32434 12.34524 12.36684
## [513] 12.38900 12.41158 12.43444 12.45743 12.48042 12.50325 12.52579 12.54789
## [521] 12.56942 12.59022 12.61016 12.62909 12.64688 12.66337 12.67843 12.69192
## [529] 12.70368 12.71359 12.72149 12.72725 12.73243 12.73864 12.74577 12.75374
## [537] 12.76245 12.77178 12.78166 12.79197 12.80262 12.81352 12.82456 12.83565
## [545] 12.84669 12.85758 12.86822 12.87852 12.88837 12.89769 12.90636 12.91430
## [553] 12.92140 12.92758 12.93272 12.93673 12.93951 12.94097 12.94101 12.93953
## [561] 12.93642 12.93161 12.92450 12.91474 12.90252 12.88804 12.87149 12.85308
## [569] 12.83300 12.81145 12.78862 12.76472 12.73995 12.71449 12.68856 12.66234
## [577] 12.63603 12.60984 12.58396 12.55858 12.53391 12.51015 12.48748 12.46611
## [585] 12.44625 12.42807 12.41179 12.39760 12.38286 12.36504 12.34445 12.32142
## [593] 12.29625 12.26928 12.24083 12.21121 12.18075 12.14977 12.11858 12.08752
## [601] 12.05689 12.02703 11.99825 11.97087 11.94522 11.92161 11.90037 11.88181
## [609] 11.86626 11.85404 11.84337 11.83228 11.82085 11.80915 11.79725 11.78520
## [617] 11.77309 11.76097 11.74891 11.73699 11.72527 11.71382 11.70270 11.69198
## [625] 11.68174 11.67203 11.66293 11.65451 11.64682 11.63995 11.63395 11.62889
## [633] 11.62485 11.62189 11.62008 11.61948 11.62016 11.62282 11.62798 11.63544
## [641] 11.64501 11.65650 11.66970 11.68444 11.70050 11.71771 11.73586 11.75477
## [649] 11.77423 11.79405 11.81405 11.83402 11.85378 11.87312 11.89186 11.90979
## [657] 11.92674 11.94249 11.95687 11.96967 11.98254 11.99717 12.01343 12.03118
## [665] 12.05030 12.07066 12.09213 12.11457 12.13786 12.16187 12.18646 12.21151
## [673] 12.23689 12.26246 12.28810 12.31367 12.33904 12.36410 12.38869 12.41271
## [681] 12.43600 12.45845 12.47993 12.50030 12.51943 12.53720 12.55347 12.56811
## [689] 12.58189 12.59567 12.60943 12.62315 12.63683 12.65044 12.66398 12.67743
## [697] 12.69078 12.70402 12.71713 12.73010 12.74291 12.75555 12.76801 12.78028
## [705] 12.79234 12.80418 12.81579 12.82714 12.83824 12.84906 12.85959 12.86982
## [713] 12.87974 12.88933 12.89865 12.90776 12.91666 12.92537 12.93386 12.94216
## [721] 12.95025 12.95814 12.96583 12.97331 12.98060 12.98769 12.99458 13.00127
## [729] 13.00777 13.01406 13.02016 13.02607 13.03178 13.03730 13.04262 13.04775
## [737] 13.05269 13.05743 13.06197 13.06632 13.07046 13.07440 13.07814 13.08168
## [745] 13.08503 13.08817 13.09111 13.09385 13.09640 13.09874 13.10089 13.10283
## [753] 13.10458 13.10612 13.10747 13.10862 13.10957 13.11032 13.11087 13.11122
## [761] 13.11137 13.11133 13.11109 13.11035 13.10889 13.10674 13.10398 13.10065
## [769] 13.09683 13.09257 13.08793 13.08297 13.07774 13.07232 13.06675 13.06110
## [777] 13.05542 13.04978 13.04423 13.03884 13.03366 13.02875 13.02418 13.01999
## [785] 13.01626 13.01304 13.00978 13.00592 13.00151 12.99661 12.99125 12.98549
## [793] 12.97939 12.97297 12.96631 12.95944 12.95242 12.94528 12.93810 12.93090
## [801] 12.92375 12.91668 12.90976 12.90302 12.89652 12.89031 12.88444 12.87895
## [809] 12.87389 12.86932 12.86528 12.86182 12.85899 12.85684 12.85500 12.85306
## [817] 12.85105 12.84898 12.84687 12.84472 12.84257 12.84041 12.83827 12.83616
## [825] 12.83410 12.83211 12.83020 12.82838 12.82667 12.82508 12.82364 12.82235
## [833] 12.82124 12.82032 12.81960 12.81909 12.81883 12.81881 12.81906 12.81959
## [841] 12.82028 12.82102 12.82182 12.82267 12.82359 12.82458 12.82565 12.82681
## [849] 12.82806 12.82941 12.83087 12.83245 12.83414 12.83596 12.83792 12.84001
## [857] 12.84226 12.84465 12.84721 12.84994 12.85285 12.85593 12.85920 12.86267
## [865] 12.86633 12.87017 12.87419 12.87839 12.88277 12.88732 12.89204 12.89693
## [873] 12.90197 12.90718 12.91254 12.91805 12.92371 12.92952 12.93547 12.94155
## [881] 12.94778 12.95413 12.96061 12.96722 12.97394 12.98079 12.98775 12.99482
## [889] 13.00200 13.00928 13.01667
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 891)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.02274 12.01702 12.01138 12.00583 12.00037 11.99499 11.98970 11.98450
## [9] 11.97938 11.97435 11.96941 11.96455 11.95979 11.95510 11.95051 11.94600
## [17] 11.94158 11.93724 11.93300 11.92884 11.92476 11.92078 11.91688 11.91307
## [25] 11.90934 11.90571 11.90216 11.89870 11.89532 11.89204 11.88884 11.88573
## [33] 11.88270 11.87977 11.87692 11.87416 11.87149 11.86891 11.86641 11.86400
## [41] 11.86168 11.85945 11.85731 11.85525 11.85329 11.85141 11.84962 11.84792
## [49] 11.84630 11.84478 11.84334 11.84200 11.84074 11.83957 11.83849 11.83749
## [57] 11.83659 11.83580 11.83514 11.83461 11.83422 11.83395 11.83380 11.83378
## [65] 11.83388 11.83410 11.83444 11.83489 11.83545 11.83612 11.83691 11.83780
## [73] 11.83879 11.83989 11.84108 11.84238 11.84377 11.84525 11.84683 11.84850
## [81] 11.85025 11.85209 11.85402 11.85602 11.85811 11.86027 11.86251 11.86482
## [89] 11.86721 11.86966 11.87218 11.87476 11.87741 11.88012 11.88289 11.88571
## [97] 11.88859 11.89152 11.89450 11.89753 11.90061 11.90373 11.90689 11.91009
## [105] 11.91333 11.91661 11.92008 11.92388 11.92801 11.93245 11.93719 11.94220
## [113] 11.94748 11.95301 11.95877 11.96475 11.97094 11.97732 11.98387 11.99058
## [121] 11.99744 12.00443 12.01154 12.01874 12.02604 12.03340 12.04083 12.04829
## [129] 12.05578 12.06328 12.07078 12.07827 12.08572 12.09312 12.10046 12.10772
## [137] 12.11490 12.12196 12.12891 12.13572 12.14384 12.15458 12.16768 12.18292
## [145] 12.20003 12.21879 12.23894 12.26023 12.28244 12.30530 12.32859 12.35205
## [153] 12.37543 12.39851 12.42103 12.44274 12.46341 12.48279 12.50063 12.51670
## [161] 12.53074 12.54252 12.55179 12.56005 12.56893 12.57836 12.58829 12.59867
## [169] 12.60943 12.62052 12.63188 12.64346 12.65519 12.66702 12.67889 12.69074
## [177] 12.70252 12.71417 12.72562 12.73684 12.74775 12.75829 12.76842 12.77808
## [185] 12.78720 12.79572 12.80361 12.81078 12.81719 12.82278 12.82749 12.83127
## [193] 12.83405 12.83579 12.83641 12.83587 12.83411 12.83106 12.82606 12.81857
## [201] 12.80878 12.79685 12.78298 12.76734 12.75010 12.73145 12.71156 12.69062
## [209] 12.66879 12.64625 12.62320 12.59979 12.57622 12.55265 12.52927 12.50626
## [217] 12.48379 12.46204 12.44119 12.42142 12.40291 12.38582 12.37035 12.35667
## [225] 12.34301 12.32760 12.31058 12.29213 12.27240 12.25154 12.22972 12.20709
## [233] 12.18382 12.16005 12.13596 12.11169 12.08741 12.06328 12.03944 12.01607
## [241] 11.99332 11.97135 11.95032 11.93038 11.91169 11.89442 11.87872 11.86387
## [249] 11.84908 11.83433 11.81964 11.80501 11.79044 11.77594 11.76152 11.74718
## [257] 11.73292 11.71875 11.70468 11.69071 11.67684 11.66307 11.64943 11.63590
## [265] 11.62249 11.60922 11.59608 11.58307 11.57021 11.55750 11.54494 11.53254
## [273] 11.52030 11.50853 11.49749 11.48714 11.47742 11.46828 11.45969 11.45158
## [281] 11.44391 11.43662 11.42968 11.42302 11.41661 11.41038 11.40430 11.39831
## [289] 11.39237 11.38642 11.38041 11.37430 11.36804 11.36157 11.35485 11.34783
## [297] 11.34045 11.33274 11.32473 11.31647 11.30800 11.29937 11.29064 11.28183
## [305] 11.27300 11.26420 11.25546 11.24683 11.23837 11.23011 11.22210 11.21439
## [313] 11.20702 11.20003 11.19348 11.18741 11.18186 11.17687 11.17251 11.16880
## [321] 11.16579 11.16354 11.16088 11.15672 11.15124 11.14460 11.13699 11.12856
## [329] 11.11950 11.10996 11.10013 11.09017 11.08026 11.07056 11.06124 11.05249
## [337] 11.04446 11.03732 11.03126 11.02644 11.02303 11.02120 11.02112 11.02297
## [345] 11.02691 11.03289 11.04066 11.05011 11.06113 11.07361 11.08742 11.10245
## [353] 11.11860 11.13574 11.15377 11.17257 11.19202 11.21201 11.23243 11.25316
## [361] 11.27409 11.29511 11.31610 11.33695 11.35754 11.37776 11.39750 11.41664
## [369] 11.43507 11.45268 11.46934 11.48495 11.50126 11.51996 11.54085 11.56374
## [377] 11.58844 11.61475 11.64246 11.67140 11.70135 11.73214 11.76355 11.79540
## [385] 11.82749 11.85962 11.89160 11.92324 11.95433 11.98469 12.01411 12.04241
## [393] 12.06937 12.09482 12.11856 12.14038 12.16010 12.17752 12.19244 12.20613
## [401] 12.21998 12.23394 12.24794 12.26196 12.27593 12.28981 12.30355 12.31711
## [409] 12.33043 12.34346 12.35616 12.36848 12.38037 12.39179 12.40267 12.41298
## [417] 12.42267 12.43168 12.43998 12.44750 12.45421 12.46005 12.46496 12.46894
## [425] 12.47203 12.47428 12.47576 12.47649 12.47654 12.47596 12.47478 12.47307
## [433] 12.47087 12.46824 12.46521 12.46185 12.45820 12.45430 12.45022 12.44600
## [441] 12.44168 12.43732 12.43298 12.42868 12.42450 12.42047 12.41665 12.41309
## [449] 12.40844 12.40147 12.39239 12.38142 12.36876 12.35463 12.33924 12.32280
## [457] 12.30551 12.28760 12.26927 12.25073 12.23220 12.21389 12.19600 12.17875
## [465] 12.16235 12.14702 12.13295 12.12037 12.10949 12.10051 12.09365 12.08733
## [473] 12.07990 12.07147 12.06215 12.05202 12.04120 12.02978 12.01788 12.00559
## [481] 11.99301 11.98026 11.96743 11.95462 11.94193 11.92948 11.91736 11.90568
## [489] 11.89453 11.88403 11.87427 11.86535 11.85739 11.85048 11.84472 11.84022
## [497] 11.83708 11.83540 11.83529 11.83690 11.84023 11.84518 11.85165 11.85954
## [505] 11.86873 11.87913 11.89063 11.90312 11.91651 11.93068 11.94553 11.96097
## [513] 11.97687 11.99315 12.00969 12.02640 12.04315 12.05986 12.07642 12.09272
## [521] 12.10866 12.12414 12.13904 12.15328 12.16673 12.17930 12.19088 12.20137
## [529] 12.21066 12.21865 12.22524 12.23032 12.23509 12.24075 12.24725 12.25449
## [537] 12.26241 12.27091 12.27994 12.28941 12.29924 12.30936 12.31969 12.33015
## [545] 12.34067 12.35117 12.36157 12.37180 12.38178 12.39143 12.40068 12.40944
## [553] 12.41764 12.42521 12.43207 12.43814 12.44334 12.44760 12.45084 12.45299
## [561] 12.45396 12.45368 12.45220 12.44967 12.44616 12.44175 12.43651 12.43050
## [569] 12.42380 12.41649 12.40862 12.40028 12.39154 12.38246 12.37312 12.36359
## [577] 12.35394 12.34425 12.33458 12.32501 12.31561 12.30645 12.29760 12.28913
## [585] 12.28111 12.27363 12.26674 12.26052 12.25328 12.24346 12.23130 12.21707
## [593] 12.20103 12.18342 12.16450 12.14454 12.12377 12.10247 12.08088 12.05926
## [601] 12.03787 12.01696 11.99679 11.97761 11.95968 11.94326 11.92859 11.91594
## [609] 11.90556 11.89771 11.89091 11.88355 11.87570 11.86742 11.85878 11.84985
## [617] 11.84069 11.83136 11.82194 11.81248 11.80305 11.79372 11.78455 11.77562
## [625] 11.76697 11.75869 11.75083 11.74346 11.73664 11.73045 11.72494 11.72019
## [633] 11.71625 11.71320 11.71109 11.71000 11.70999 11.71161 11.71526 11.72079
## [641] 11.72801 11.73677 11.74689 11.75822 11.77058 11.78381 11.79773 11.81219
## [649] 11.82702 11.84204 11.85710 11.87203 11.88665 11.90081 11.91433 11.92705
## [657] 11.93881 11.94943 11.95874 11.96659 11.97414 11.98261 11.99193 12.00202
## [665] 12.01283 12.02426 12.03626 12.04875 12.06166 12.07492 12.08845 12.10218
## [673] 12.11605 12.12997 12.14388 12.15770 12.17137 12.18480 12.19794 12.21070
## [681] 12.22302 12.23482 12.24603 12.25657 12.26639 12.27540 12.28353 12.29072
## [689] 12.29727 12.30358 12.30966 12.31552 12.32117 12.32662 12.33190 12.33700
## [697] 12.34195 12.34677 12.35145 12.35602 12.36049 12.36486 12.36917 12.37341
## [705] 12.37761 12.38176 12.38590 12.39003 12.39416 12.39831 12.40249 12.40672
## [713] 12.41100 12.41535 12.41955 12.42337 12.42685 12.43001 12.43288 12.43548
## [721] 12.43785 12.44000 12.44196 12.44376 12.44543 12.44699 12.44848 12.44991
## [729] 12.45131 12.45272 12.45414 12.45563 12.45719 12.45886 12.46066 12.46262
## [737] 12.46476 12.46702 12.46931 12.47162 12.47393 12.47624 12.47854 12.48083
## [745] 12.48310 12.48533 12.48752 12.48966 12.49175 12.49378 12.49573 12.49760
## [753] 12.49938 12.50106 12.50264 12.50411 12.50545 12.50667 12.50775 12.50868
## [761] 12.50946 12.51008 12.51053 12.51085 12.51107 12.51120 12.51125 12.51123
## [769] 12.51113 12.51096 12.51073 12.51044 12.51010 12.50971 12.50927 12.50880
## [777] 12.50829 12.50775 12.50718 12.50660 12.50600 12.50539 12.50477 12.50415
## [785] 12.50354 12.50293 12.50222 12.50130 12.50018 12.49887 12.49740 12.49578
## [793] 12.49403 12.49215 12.49017 12.48810 12.48595 12.48375 12.48150 12.47922
## [801] 12.47694 12.47465 12.47238 12.47014 12.46795 12.46583 12.46379 12.46183
## [809] 12.45999 12.45828 12.45670 12.45528 12.45403 12.45297 12.45197 12.45089
## [817] 12.44974 12.44853 12.44727 12.44595 12.44459 12.44320 12.44177 12.44031
## [825] 12.43884 12.43735 12.43586 12.43436 12.43287 12.43140 12.42994 12.42850
## [833] 12.42710 12.42573 12.42440 12.42312 12.42190 12.42074 12.41964 12.41862
## [841] 12.41762 12.41660 12.41555 12.41448 12.41340 12.41231 12.41120 12.41009
## [849] 12.40898 12.40787 12.40676 12.40566 12.40457 12.40350 12.40245 12.40142
## [857] 12.40041 12.39943 12.39849 12.39758 12.39671 12.39588 12.39510 12.39436
## [865] 12.39367 12.39303 12.39242 12.39185 12.39132 12.39083 12.39037 12.38995
## [873] 12.38955 12.38919 12.38885 12.38854 12.38826 12.38800 12.38776 12.38754
## [881] 12.38734 12.38716 12.38699 12.38684 12.38670 12.38657 12.38645 12.38633
## [889] 12.38623 12.38612 12.38603
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")